﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace Jacaranda.Model
{
    public class LogicalOperation : ConditionalExpression
    {
        public LogicalOperator Operator { get; set; }

        public ConditionalExpression Left { get; set; }

        public ConditionalExpression Right { get; set; }

        internal override string GenerateSql(Type propertyEntityType)
        {
            switch (Operator)
            {
                case LogicalOperator.And:
                    return string.Format("(({0}) AND ({1}))", Left.GenerateSql(propertyEntityType), Right.GenerateSql(propertyEntityType));

                case LogicalOperator.Or:
                    return string.Format("(({0}) OR ({1}))", Left.GenerateSql(propertyEntityType), Right.GenerateSql(propertyEntityType));

                case LogicalOperator.Not:
                    return string.Format("(NOT ({0}))", Left.GenerateSql(propertyEntityType));

                default:
                    return null;
            }
        }
    }
}
